package com.multysite.ajax.admin;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.NamespaceManager;
import com.multysite.entity.admin.ApplicationConfig;
import com.multysite.entity.admin.ApplicationTemplate;
import com.multysite.model.admin.ApplicationConfigModel;
import com.multysite.model.admin.ApplicationTemplateModel;

@SuppressWarnings("serial")
public class ProcessTemplate extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		System.out.println("Do get !");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String ns = NamespaceManager.get();
		ApplicationConfig config = ApplicationConfigModel.getById(ns, ns);
		ApplicationTemplate template = ApplicationTemplateModel.getById(ns,
				config.getTemplateId());
		String action = req.getParameter("action");
		String value = req.getParameter("pageValue");
		if (action != null && action.equals("homePage")) {
			template.setHome(value);
		} else if (action != null && action.equals("detailPage")) {
			template.setDetail(value);
		} else if (action != null && action.equals("tagPage")) {
			template.setTag(value);
		} else if (action != null && action.equals("categoryPage")) {
			template.setCategory(value);
		} else if (action != null && action.equals("cssFile")) {
			template.setCss(value);
		} else if (action != null && action.equals("jsFile")) {
			template.setJs(value);
		} else if (action != null && action.equals("searchPage")) {
			template.setSearch(value);
		}
		ApplicationTemplateModel.insert(ns, template);
	}
}
